<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="com.framework.entity.Global"%>
<%@ page import="com.biz.utils.ConfigUtil" %>
<%@ page import="com.framework.util.Const" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
    String resoursUrl = ConfigUtil.get("RESOURCES_URL");
%>
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="UTF-8">
<title>${goodsname}</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="format-detection" content="telephone=no">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<jsp:include page="/jsp/inc_head.jsp"></jsp:include>
<script src="<%=resoursUrl%>resources/assets/js/echo.min.js"></script>
<link rel="stylesheet"
	href="<%=resoursUrl%>resources/assets/css/echo.css">
<script type="text/javascript">
        echo.init({
            offset: 0,
            throttle: 0//设置图片延迟加载的时间
        });
    </script>
<style>
.am-modal-dialog {
	border-radius: 6px;
	background: #fff;
}

.am-modal-btn {
	color: #616161;
	background: #f7f7f7;
	border-radius: 0 0 6px 6px !important;
}

.msgs1 {
	background-color: #eee;
	color: #555;;
}

.jlqspanorange {
	background-color: #ff9f09;
	color: #fff;
	border-radius: 4px;
	display: inline-block;
	padding: 0 3px;
	font-size: 12px;
}

.am-padding-0 {
	padding-left: 0 !important;
	padding-right: 0 !important;
}

ul.spxqPzFl li {
	float: left;
	margin: 5px 5px 0 0;
	padding: 0 6px;
}

.spxqPzFl label {
	width: 100%;
	padding: 0 6px;
}

.popteladr {
	position: fixed;
	top: 50%;
	left: 50%;
	width: 300px;
	margin-left: -150px;
	margin-top: -100px;
	font-size: 12px;
	z-index: 1001;
	background-color: #fff;
	border-radius: 10px;
	padding: 30px 10px 20px;
	color: #444;
	display: none;
}

.popteltop {
	border-bottom: 1px solid #ddd;
	padding-bottom: 12px;
	text-align: center;
}

.borleft {
	border-left: 1px solid #ddd;
}

.telcall {
	display: inline-block;
	background: url(<%=basePath%>resources/assets/image/icon_calltel.png)
		no-repeat left center/14px 14px;
	padding-left: 16px;
	color: #ff5a13;
}

.adrnav {
	display: inline-block;
	background: url(<%=basePath%>resources/assets/image/icon_adrnav.png)
		no-repeat left center/14px 16px;
	padding-left: 16px;
	color: #ff5a13;
}

.kefuimg {
	position: absolute;
	top: -25px;
	left: 125px;
}

.closepop {
	position: absolute;
	right: 0;
	top: -30px;
}

.kefuimg img {
	height: 50px;
	width: 50px;
	border-radius: 100%;
}

.zzc {
	position: fixed;
	left: 0;
	top: 0;
	bottom: 0;
	right: 0;
	height: 100%;
	width: 100%;
	z-index: 1000;
	background-color: #000;
	opacity: 0.7;
	display: none;
}
</style>
</head>
<body>
	<!--slide start-->
	<div class="am-g" id="scwrapper">
		<div class="main_visual" id="swiper_wrapper">
			<div class="flicking_con hd">
				<ul></ul>
			</div>
			<div class="main_image bd">
				<div class="tempWrap">
					<ul>
						<c:forEach items="${goodsPics}" var="obj" varStatus="vs">
							<li><c:choose>
									<c:when test="${obj.mainType == '3'}">
										<img src="<%=Global.OSSURL_MAINTYPE3%>/${obj.path}">
									</c:when>
									<c:otherwise>
										<img src="<%=Global.OSSURL%>/${obj.path}">
									</c:otherwise>
								</c:choose>
							</li>
						</c:forEach>
					</ul>
				</div>
			</div>
		</div>
	</div>

	<script>
    TouchSlide({
        slideCell:"#swiper_wrapper",
        titCell:".hd ul", //开启自动分页 autoPage:true ，此时设置 titCell 为导航元素包裹层
        mainCell:".bd ul",
        effect:"leftLoop",
        autoPlay:true,//自动播放
        autoPage:true, //自动分页
        switchLoad:"_src" //切换加载，真实图片路径为"_src"
    });
</script>
	<!--slide end-->

	<section class="am-g">
		<div class="am-u-sm-12 spxqSpTitle">${goodsname}</div>
		<div class="am-u-sm-12 am-padding-bottom">
			<div class="am-u-sm-7 am-padding-0">
				<div class="am-u-sm-12 am-padding-0 spxqPrice" id="price">￥0</div>
				<%--<div class="am-u-sm-12 am-padding-0 spxqYf">运费：￥0.00(暂时没有设置)</div>--%>
				<div class="am-u-sm-12 am-padding-0 spxqYf" id="goodsStockNum">库存
				</div>
			</div>
			<div class="am-u-sm-5 am-padding-0 am-margin-top-xs">
				<div class="am-u-sm-4 minplstyle" id="minus_cart">
					<i class="am-icon-minus"></i>
				</div>
				<div class="am-u-sm-4 am-padding-0" style="height:27px;">
					<input type="text" class="buycount" value="1" id="buycount"
						readonly="readonly">
				</div>
				<div class="am-u-sm-4 maxplstyle" id="plus_cart">
					<i class="am-icon-plus"></i>
				</div>
			</div>
		</div>
		<%--    <a href="" class="am-u-sm-12 spxqWzfx">
    	<div class="am-u-sm-11 am-padding-0">
            <img src="<%=basePath %>resources/assets/images/wzfxicon.png" width="17"> &nbsp;
            <span class="am-text-middle">玩转分销--他人下单，你领红包</span>
        </div>
        <div class="am-u-sm-1 am-padding-0 am-text-right"><i class="am-header-icon am-icon-angle-right am-icon-sm"></i></div>
    </a>--%>
		<!-- 分类属性 -->
		<ul class="am-u-sm-12 spxqPzFl" id="type">

		</ul>

		<!-- 商品详情 -->
		<div class="am-u-sm-12 spxqTwhpDiv">
			<div class="am-u-sm-12 am-padding-0 am-text-center">
				<img
					src="<%=resoursUrl%>resources/assets/images/spxqline.png"
					style="width:75%">
			</div>
			<div class="am-u-sm-12 am-padding-0 am-text-center am-margin-top-sm">
				${goodsInfo}</div>
		</div>
	</section>

	<!--footer-->
	<div class="am-g gdDbdiv"></div>
	<div class="footeNavbar">
		<div class="am-u-sm-12 am-padding-0">
			<c:choose>
				<c:when test="${isTicket == '0'}">
					<div class="am-u-sm-2 am-padding-0">
						<a>
							<div class="am-u-sm-12 am-padding-0" onClick="toHome()">
								<div class="am-u-sm-12" style="padding: 4px 0 0;">
									<img
										src="<%=resoursUrl%>resources/assets/images/homeicon.png" />
								</div>
								<div class="am-u-sm-12 am-padding-0 am-text-xs">首页</div>
							</div> </a>
					</div>
					<div class="am-u-sm-2 am-padding-0">
						<a>
							<div class="am-u-sm-12 am-padding-0" onclick="addcollection()">
								<div class="am-u-sm-12" style="padding: 4px 0 0;">
									<img id="collectionpic"
										src="<%=resoursUrl%>resources/assets/images/collecticon.png"
										height="18" />
								</div>
								<div class="am-u-sm-12 am-padding-0 am-text-xs"
									id="collectionname">收藏</div>
							</div> <input type="hidden" id="collectionstate"
							value="${collectionstate}" /> </a>
					</div>
					<div class="am-u-sm-2 am-padding-0">
						<a href="javascript:" class="openpop">
							<div class="am-u-sm-12 am-padding-0">
								<div class="am-u-sm-12" style="padding: 4px 0 0;">
									<img
										src="<%=resoursUrl%>resources/assets/images/qqicon.png" />
								</div>
								<div class="am-u-sm-12 am-padding-0 am-text-xs">客服</div>
							</div> </a>
					</div>
					<a class="am-u-sm-3 spxqJrgwcBtn" id="cartstate"
						onclick="addcart();">加入购物车</a>
					<a class="am-u-sm-3 spxqljgmBtn" id="buystate" onclick="buyNow();">立即购买</a>
				</c:when>
				<c:otherwise>
					<div class="am-u-sm-2 am-padding-0">
						<a>
							<div class="am-u-sm-12 am-padding-0" onClick="toHome()">
								<div class="am-u-sm-12" style="padding: 4px 0 0;">
									<img
										src="<%=resoursUrl%>resources/assets/images/homeicon.png" />
								</div>
								<div class="am-u-sm-12 am-padding-0 am-text-xs">首页</div>
							</div> </a>
					</div>
					<div class="am-u-sm-2 am-padding-0">
						<a>
							<div class="am-u-sm-12 am-padding-0" onclick="addcollection()">
								<div class="am-u-sm-12" style="padding: 4px 0 0;">
									<img id="collectionpic"
										src="<%=resoursUrl%>resources/assets/images/collecticon.png"
										height="18" />
								</div>
								<div class="am-u-sm-12 am-padding-0 am-text-xs"
									id="collectionname">收藏</div>
							</div> <input type="hidden" id="collectionstate"
							value="${collectionstate}" /> </a>
					</div>
					<div class="am-u-sm-2 am-padding-0">
						<a href="javascript:" class="openpop">
							<div class="am-u-sm-12 am-padding-0">
								<div class="am-u-sm-12" style="padding: 4px 0 0;">
									<img
										src="<%=resoursUrl%>resources/assets/images/qqicon.png" />
								</div>
								<div class="am-u-sm-12 am-padding-0 am-text-xs">客服</div>
							</div> </a>
					</div>
					<%--<a  class="am-u-sm-3 spxqJrgwcBtn" id="cartstate" style="background-color:#eee;">加入购物车</a>--%>
					<a class="am-u-sm-6 spxqljgmBtn" id="buystate" onclick="buyNow();">立即购买</a>
				</c:otherwise>
			</c:choose>
		</div>
	</div>
	<!--footer-->

	<!--联系商家弹出-->
	<%--<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
  <div class="am-modal-dialog">
    <div class="am-u-sm-12">
        <div class="am-padding-0 lxsjTcTel">
           <div class="am-u-sm-7 am-padding-0 am-text-left">0411-83895189</div>
           <a href="tel:0411-83895189" class="am-u-sm-5 am-padding-0 am-text-right">呼叫</a>
        </div>
       &lt;%&ndash; <div class="am-padding-0 lxsjTcTel">
           <div class="am-u-sm-7 am-padding-0 am-text-left">13773501717</div>
           <a href="tel:13773501717" class="am-u-sm-5 am-padding-0 am-text-right">呼叫</a>
        </div>&ndash;%&gt;
    </div>
    <div class="am-modal-footer">
      <span class="am-modal-btn">关闭</span>
    </div>
  </div>
</div>--%>

	<!--联系商家弹出电话导航-->
	<div class="popteladr">
		<span class="closepop"><img
			src="<%=resoursUrl%>resources/assets/image/icon_close.png"
			height="20" /> </span>
		<div class="popteltop">
			<c:if test="${logo_url != ''}">
				<span class="kefuimg"><img src="${logo_url }" /> </span>
			</c:if>
			<c:if test="${logo_url == ''}">
				<span class="kefuimg"><img
					src="<%=resoursUrl%>resources/assets/image/pic-murenimg.png" />
				</span>
			</c:if>
			<div class="">${venderIdName}</div>
		</div>
		<div class="am-u-sm-12 am-pad-none kftelandadr am-margin-top-xs">

			<div class="am-u-sm-3 am-pad-none">
				<a href="tel:010-25445632" class="">客服电话:</a>
			</div>
			<div class="am-u-sm-7 am-pad-none">
				<a href="tel:010-25445632" class="">010-25445632</a>
			</div>
			<div class="am-u-sm-2 am-pad-none am-text-right borleft">
				<a href="tel:010-25445632" class="telcall">拨打 </a>
			</div>

		</div>
		<div class="am-u-sm-12 am-pad-none kftelandadr am-margin-top-xs">
			<a target="_blank"
				href="${pageContext.request.contextPath}/client_toMendian.do?venderId=${venderId} ">
				<div class="am-u-sm-3 am-pad-none">商家地址:</div>
				<div class="am-u-sm-7 am-pad-none">${venderAddr}</div>
				<div class="am-u-sm-2 am-pad-none am-text-right borleft">
					<span class="adrnav">导航 </span>
				</div> </a>
		</div>
	</div>
	<div class="zzc"></div>
	<script>
    $(".closepop").click(function(){
        $(".popteladr,.zzc").hide();
    });
    $(".openpop").click(function(){
        $(".popteladr,.zzc").show();
    });
</script>


	<!-- form提交 -->
	<form id="goToGoodsDetail">
		<input id="form_goodsId" type="hidden" name="goodsId" value="${goodsid}" /> 
		<input id="form_shopId" type="hidden" name="shopId" value="${shopid}" /> 
		<input id="form_type1"	type="hidden" name="type1" />
		<input id="form_type2" type="hidden" name="type2" /> 
		<input id="form_type3" type="hidden" name="type3" />
		<input id="form_typesId1" type="hidden" name="typesId1"	value="${typesId1}" /> 
		<input id="form_typesId2" type="hidden"	name="typesId2" value="${typesId2}" /> 
		<input id="form_typesId3" type="hidden" name="typesId3" value="${typesId3}" /> 
		<input id="form_price" type="hidden" name="price" /> 
		<input id="form_count" type="hidden" name="count" value="1" /> 
		<input id="form_buytype" type="hidden" name="buytype" />
	</form>

	<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert-1">
		<div class="am-modal-dialog">
			<div class="am-modal-hd" id="alert_title_1">提示</div>
			<div class="am-modal-bd" id="alert_message_1"></div>
			<div class="am-modal-footer" id="alertspan1">
				<span class="am-modal-btn">确定</span>
			</div>
			<div class="am-modal-footer" id="alertspan2" style="display:none;">
				<span class="am-u-sm-6 am-modal-btn am-btn-xs"
					style="background:#ffbe23;">继续购物</span> <span
					class="am-u-sm-6 am-modal-btn am-btn-xs"
					style="background:#ff6060;" onClick="toOrderCart();">去付款>></span>
			</div>
		</div>
	</div>
	<script>
var ajaxpath="${pageContext.request.contextPath}";
var goodsjson=[];//存放商品的价格库存与相应的type以及上下架信息
var goodsnum=0;//goodsjson数据数量
var typejson=[];//存放商品的分类
var typenum=0;//typejson中数据数量
var stype=${stype};

$(function(){
     //一次性加载信息
    querygoodsPrice();  //加载价格库存
	querygoodsDetailInfo();   //加载商品分类信息
	loudpage();//拼装页面
	loudcollection();//加载是否收藏
});

function querygoodsDetailInfo(){
     var goodsid=$("#form_goodsId").val();
     $.ajax({
			url:ajaxpath+"/shop/getgoodsDetailInfo.do?goodsid="+ goodsid,
			type : 'post',
			async: false,
			success : function(data){
				$.each(data,function(i){
		           var flag=false;
		     	   for(var j=0;j<typenum;j++){
		              if(data[i].standerdid==typejson[j].standerdid){
		                   var json={typeid:data[i].typeid,typename:data[i].typename};
		                   typejson[j].typelist.push(json);
		                   flag=true;
		              };
		           }
		           if(!flag){
		                 typejson[typenum]={standerdid:data[i].standerdid,standerdname:data[i].standerdname,typelist:[]};
		                 var json={typeid:data[i].typeid,typename:data[i].typename};
		                 typejson[typenum].typelist.push(json);
		                 typenum++;
		           };
		        });
			}
			});

}

function querygoodsPrice(){
     var goodsid=$("#form_goodsId").val();
     $.ajax({
			url:ajaxpath+"/shop/querygoodsPrice.do?goodsid="+ goodsid,
			type : 'post',
			async: false,
			success : function(data){
				$.each(data,function(i){
		     		goodsjson[goodsnum]={id:data[i].id,type1:data[i].type1,type2:data[i].type2,type3:data[i].type3,typesId1:data[i].typesId1,typesId2:data[i].typesId2,typesId3:data[i].typesId3,price:data[i].price,stockNow:data[i].stockNow,isSale:data[i].isSale,isTicket:data[i].isTicket};
		            goodsnum++;
     	        });
			}
	 });
}

//拼装页面
function loudpage(){
     html="";
     for (var i=0;i<typenum;i++){
          html+='<div class="am-u-sm-12 am-padding-0">'+
                '<div class="am-u-sm-2 am-padding-0 am-text-left" style="width:12%;margin-top:7px;">'+typejson[i].standerdname+'</div>'+
                '<div class="am-u-sm-10 am-padding-0" style="width:88%">';
         
          //此处拼装页面分为是否需要匹配分组两个判断，以后分组这块页面修改时需要判断是否两个分支都要修改
          if(stype==1){//需要匹配分组信息
               var typesId1=$("#form_typesId1").val();
		       var typesId2=$("#form_typesId2").val();
		       var typesId3=$("#form_typesId3").val();
		       var goodstype1="";
		       var goodstype2="";
		       var goodstype3="";
		       for(var k=0;k<goodsnum;k++){
		          if((typesId1==goodsjson[k].typesId1||typesId1=="")&&(typesId2==goodsjson[k].typesId2||typesId2=="")&&(typesId3==goodsjson[k].typesId3||typesId3=="")){
		              goodstype1=goodsjson[k].type1;
			          goodstype2=goodsjson[k].type2;
			          goodstype3=goodsjson[k].type3; 
		          };
		       }
		         
               for (var j=0;j<typejson[i].typelist.length;j++){
	              if(typejson[i].typelist[j].typeid==goodstype1||typejson[i].typelist[j].typeid==goodstype2||typejson[i].typelist[j].typeid==goodstype3){
		              html+='<div class="am-u-sm-4 am-padding-0 am-text-left am-u-end am-margin-bottom" onclick="loudprice('+i+',\''+typejson[i].typelist[j].typeid+'\');">'+
			                '<input type="radio" name="'+i+'radio" id="'+typejson[i].typelist[j].typeid+'" checked>'+
			                '<label  for="'+typejson[i].typelist[j].typeid+'">'+typejson[i].typelist[j].typename+'</label>'+
		                    '</div>';
	              }else{
	                  html+='<div class="am-u-sm-4 am-padding-0 am-text-left am-u-end am-margin-bottom" onclick="loudprice('+i+',\''+typejson[i].typelist[j].typeid+'\');">'+
			                '<input type="radio" name="'+i+'radio" id="'+typejson[i].typelist[j].typeid+'">'+
			                '<label  for="'+typejson[i].typelist[j].typeid+'">'+typejson[i].typelist[j].typename+'</label>'+
		                    '</div>';
	              };
	           };
          }else {//不用匹配分组信息，默认第一个选中
               for (var j=0;j<typejson[i].typelist.length;j++){
	              if(j==0){
		              html+='<li onclick="loudprice('+i+',\''+typejson[i].typelist[j].typeid+'\');">'+
			                '<input type="radio" name="'+i+'radio" id="'+typejson[i].typelist[j].typeid+'" checked>'+
			                '<label  for="'+typejson[i].typelist[j].typeid+'">'+typejson[i].typelist[j].typename+'</label>'+
		                    '</li>';
	              }else{
	                  html+='<li onclick="loudprice('+i+',\''+typejson[i].typelist[j].typeid+'\');">'+
			                '<input type="radio" name="'+i+'radio" id="'+typejson[i].typelist[j].typeid+'">'+
			                '<label  for="'+typejson[i].typelist[j].typeid+'">'+typejson[i].typelist[j].typename+'</label>'+
		                    '</li>';
	              };
	           };
          }
            
          html+='</div></div>';    
     }
     $("#type").html(html);
     loudprice();//匹配库存与价格
}

//匹配库存与价格
function loudprice(num,typeid){
     var type1=$("input[type=radio][name='0radio']:checked").attr("id");
     var type2=$("input[type=radio][name='1radio']:checked").attr("id");
     var type3=$("input[type=radio][name='2radio']:checked").attr("id");
     if(num==0){
         type1=typeid;
     }else if(num==1){
         type2=typeid;
     }else if(num==2){
         type3=typeid;
     }
     for (var i=0;i<goodsnum;i++){
          var flag1=false;
          var flag2=false;
          var flag3=false;
          var goodstype1=goodsjson[i].type1;
          var goodstype2=goodsjson[i].type2;
          var goodstype3=goodsjson[i].type3;
          if(goodstype1==""||goodstype1=="null"){
              flag1=true;
          }else if(goodstype1==type1||goodstype1==type2||goodstype1==type3){
              flag1=true;
          }
          if(goodstype2==""||goodstype2=="null"){
              flag2=true;
          }else if(goodstype2==type1||goodstype2==type2||goodstype2==type3){
              flag2=true;
          }
     	  if(goodstype3==""||goodstype3=="null"){
              flag3=true;
          }else if(goodstype3==type1||goodstype3==type2||goodstype3==type3){
              flag3=true;
          }
          if(flag1&&flag2&&flag3){
               $("#form_type1").val(goodsjson[i].type1);
               $("#form_type2").val(goodsjson[i].type2);
               $("#form_type3").val(goodsjson[i].type3);
               $("#form_typesId1").val(goodsjson[i].typesId1);
               $("#form_typesId2").val(goodsjson[i].typesId2);
               $("#form_typesId3").val(goodsjson[i].typesId3);
              if(goodsjson[i].isTicket==1)
              { $("#price").html("￥"+goodsjson[i].price);
              }else
              {

                  $("#price").html('<span class="jlqspanorange">久零券</span><span class="colred11">'+goodsjson[i].price+'券</span>');
              }
              $("#goodsStockNum").html("库存："+goodsjson[i].stockNow);

               $("#form_price").val(goodsjson[i].price);
               if(goodsjson[i].isSale==0){
                    $("#buystate").html("商品已下架");
                    $("#buystate").attr("disabled", true);
                    $("#buystate").addClass("msgs1");
                    $("#cartstate").attr("disabled", true);
                    $("#cartstate").addClass("msgs1");
               }else if(goodsjson[i].stockNow==0){
                    $("#buystate").html("商品已售罄"); 
                    $("#buystate").attr("disabled", true); 
                    $("#buystate").addClass("msgs1");
                    $("#cartstate").attr("disabled", true);
                    $("#cartstate").addClass("msgs1");
               }else{
                    $("#buystate").html("立即购买"); 
                    $("#buystate").attr("disabled", false);
                    $("#buystate").removeClass("msgs1");
                    $("#cartstate").attr("disabled", false);
                    $("#cartstate").removeClass("msgs1");
               };
          };
     };
}

function loudcollection(){
     var collectionstate=$("#collectionstate").val();
     if(collectionstate==1){
       document.getElementById("collectionpic").src ="<%=resoursUrl%>resources/assets/images/collecticon2.png";
       $("#collectionname").addClass("ckicontext");
     };
}

//加入购物车
function addcart(){

if(!issessionUserid()){
return;
}

   var dis= $("#cartstate").attr("disabled");
    if(dis!="disabled"){
     $("#form_buytype").val("1");
     $.ajax({
                type: "POST",
                url:ajaxpath+"/shop/insertMycart.do?",
                data:$("#goToGoodsDetail").serialize(),// 你的formid
                async: false,
                success: function(data) {
                    if(data.result=="success"){
                        $("#alert_message_1").html("加入购物车成功！");
                        $("#alertspan1").hide();
                        $("#alertspan2").show();
						$("#my-alert-1").modal('open'); 
                    }else{
                        $("#alert_message_1").html("加入购物车失败,请稍后再试！");
                        $("#alertspan1").show();
                        $("#alertspan2").hide();
						$("#my-alert-1").modal('open');
                    };
                }
      });
    };
}

//立即购买
function buyNow(){
    var dis= $("#buystate").attr("disabled");
    if(dis!="disabled") {
        $("#form_buytype").val("3");
        
        //判断是否有用户信息，如果没绑定则跳转注册页面
      var sesStr ='<%=(String) session.getAttribute(Const.SESSION_USER_LOGINNAME)%>';
      if (sesStr == null || sesStr == '' || sesStr == 'null') {
					var jsonstring = encodeURI(encodeURI(toJson()));
					alert("未绑定手机，绑定后操作");
					window.location.href = ajaxpath	+ "/jsp/client/account_change.jsp?type=1&jsonstring="+ jsonstring + "&guid=" + new Date();
					return;
				}

				$.ajax({
					type : "POST",
					url : ajaxpath + "/shop/insertMycart.do?",
					data : $("#goToGoodsDetail").serialize(),// 你的formid
					async : false,
					success : function(data) {
						if (data.result == "success") {
							window.location.href = ajaxpath
									+ "/order/toOrderConfirm.do?type=" + "1"
									+ "&cartid=" + data.cartid;
						} else {
							$("#alert_message_1").html("立即购买失败,请稍后再试！");
							$("#alertspan1").show();
							$("#alertspan2").hide();
							$("#my-alert-1").modal('open');
						}
						;
					}
				});
			}
			;
		}

		//收藏与取消收藏
		function addcollection() {
			var collectionstate = $("#collectionstate").val();

			if (collectionstate == 0) {//收藏
			if(!issessionUserid()){
			return;
			}
				$
						.ajax({
							type : "POST",
							url : ajaxpath + "/shop/insertMycollection.do?",
							data : $("#goToGoodsDetail").serialize(),// 你的formid
							async : false,
							success : function(data) {
								if (data.result == "success") {
									$("#collectionstate").val("1");
									document.getElementById("collectionpic").src = "<%=resoursUrl%>resources/assets/images/collecticon2.png";
						$("#collectionname").addClass("ckicontext");
                    }else{
                        $("#alert_message_1").html("收藏失败,请稍后再试！");
                        $("#alertspan1").show();
                        $("#alertspan2").hide();
						$("#my-alert-1").modal('open');
                    };
                }
            });
     }else{ //取消收藏
            $.ajax({
                type: "POST",
                url:ajaxpath+"/shop/deleteMycollection.do?",
                data:$("#goToGoodsDetail").serialize(),// 你的formid
                async: false,
                success: function(data) {
                    if(data.result=="success"){
                        $("#collectionstate").val("0");
                        document.getElementById("collectionpic").src ="<%=resoursUrl%>resources/assets/images/collecticon.png";
									$("#collectionname").removeClass(
											"ckicontext");
								} else {
									$("#alert_message_1").html("取消收藏失败,请稍后再试！");
									$("#alertspan1").show();
									$("#alertspan2").hide();
									$("#my-alert-1").modal('open');
								}
								;
							}
						});
			}
			;
		}

		//跳转首页
		function toHome() {
			window.location.href = ajaxpath + "/client_toHomeScreen.do";
		}

		//加减JS
		$("#plus_cart").click(function() {
			var now_num = $("#buycount").val();
			$("#form_count").val(parseInt(now_num) + 1);
			$("#buycount").val(parseInt(now_num) + 1);
		});

		$("#minus_cart").click(function() {
			var now_num = $("#buycount").val();
			if (now_num == 1) {
				return false;
			} else {
				$("#form_count").val(parseInt(now_num) - 1);
				$("#buycount").val(parseInt(now_num) - 1);
			}
			;
		});

		function toJson() {
			var	goodsId = $("#form_goodsId").val();
			var	shopId = $("#form_shopId").val();
			var	typesId1 = $("#form_typesId1").val();
			var	typesId2 = $("#form_typesId2").val();
			var	typesId3 = $("#form_typesId3").val();
			var	type1 = $("#form_type1").val();
			var	type2 = $("#form_type2").val();
			var	type3 = $("#form_type3").val();
			var	price = $("#form_price").val();
			var	count = $("#form_count").val();
			var	buytype = $("#form_buytype").val();
			var json_date = {
				goodsId : goodsId,
				shopId : shopId,
				typesId1 : typesId1,
				typesId2 : typesId2,
				typesId3 : typesId3,
				type1 : type1,
				type2 : type2,
				type3 : type3,
				price : price,
				count : count,
				buytype : buytype
			};
			var json_string = JSON.stringify(json_date);
			return json_string;
		}
		
		function toJson2() {
		var goodsid= $("#form_goodsId").val();
			var json_date = {
				goodsid : goodsid,
				stype : stype
			};
			var json_string = JSON.stringify(json_date);
			return json_string;
		}

		function toOrderCart() {
			window.location.href = "${pageContext.request.contextPath}/client_toMycart.do";
		}
		
		//false:未注册，true :已注册
		function issessionUserid() {
		var isnull=false;
		    //判断是否有用户信息，如果没绑定则跳转注册页面
           var sesStr ='<%=(String) session.getAttribute(Const.SESSION_USER_LOGINNAME)%>';
			if (sesStr == null || sesStr == '' || sesStr == 'null') {
				alert("未绑定手机，绑定后操作");
				var jsonstring = encodeURI(encodeURI(toJson2()));
				window.location.href = ajaxpath	+ "/jsp/client/account_change.jsp?type=2&jsonstring="+ jsonstring + "&guid=" + new Date();
			} else {
				isnull = true;
			}
			return isnull;
		};
	</script>

</body>
</html>
